/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package AplManager.controller;
import AplManager.views.*;
import AplManager.models.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
/**
 *
 * @author user
 */
public class TeamSelectController {
     private TeamSelect view;
     private ArrayList<Team> dbControl;
      //private TableDisplay tableDisplayView;
     //private Team model;
    private ActionListener actionListener;
    
    public TeamSelectController(TeamSelect view, ArrayList<Team> dbControl){
        this.view  = view;
        this.dbControl = dbControl;
    }
    
    public void control(){        
        actionListener = new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) { 
                 String id ="";
                 String nme ="";
                  if(e.getSource().equals(view.selectTeam())){
                    for(int i =0; i<dbControl.size();i++){
                    if(dbControl.get(i).getTeamName().equals(view.getSelectedTeam())){
                        id = dbControl.get(i).getTeamID();
                        nme = dbControl.get(i).getTeamName();
                    }
                    }
                    TableDisplay tblView = new TableDisplay();
                   Team team = new Team(id, nme);
                  DBcontroller dControl = new DBcontroller(tblView,team);
                   dControl.set();
                  tblView.setVisible(true);
                 TableDisplayController control = new TableDisplayController(team,tblView,dControl);
                 control.control();  
                  }
              }
        };                
        view.selectTeam().addActionListener(actionListener);
    }
}
